package com.lw.syn;

import java.util.ArrayList;

/**
 * @author LW
 * @2020/8/18 14:22
 */
public class sycList {

    public static void main(String[] args) throws InterruptedException {
        ArrayList<Object> list = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                synchronized (list) {//光加锁不延时，运行快了，线程里add还没运行完就开始打印语句
                    //集合无法全部被线程记录
                    list.add(Thread.currentThread().getName());
                }
            }).start();
        }
        Thread.sleep(100);
        System.out.println(list.size());

    }
}
